<template>
  <div class="app-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span class="el-icon-document">基础信息</span>
        <el-button style="float: right;" type="primary" @click="goBack">
          返回
        </el-button>
      </div>
      <!--初始化流程加载问卷信息-->
      <biz-project-form
        v-if="formConf.formKey"
        :key="new Date().getTime()"
        :form-config="formConf"
        @submit="submitForm"
      />
    </el-card>
  </div>
</template>

<script>
import BizProjectForm from '@/formgen/src/components/BizProjectForm'
import mixin from "../../../form/TduckFormMixin"
import {getBusinessFormRequest} from "@/api/workflow/workflow"
import {createFormResultRequest} from "@/api/project/data"

const uaParser = require('ua-parser-js')
const ua = uaParser(navigator.userAgent)

export default {
  name: "Record",
  components: {
    BizProjectForm
  },
  mixins: [mixin],
  props: {},
  data() {
    return {
      formConf: {
        formKey: ''
      }
    }
  },
  created() {
    // 初始化问卷
    getBusinessFormRequest(this.$route.query.deployId).then((res) => {
      if (res.data) {
        this.formConf.formKey = res.data.formKey
      }
    })
  },
  methods: {
    /** 返回页面 */
    goBack() {
      // 关闭当前标签页并返回上个页面
      this.bus.$emit('onCurrentContextmenuClick', {id: 1, path: this.$route.path})
      this.$router.go(-1)
    },
    /** 申请流程问卷数据提交 */
    submitForm(data) {
      if (data) {
        // 完成时间
        createFormResultRequest({
          'completeTime': null,
          'formKey': this.formConf.formKey,
          'submitOs': ua.os.name,
          'submitBrowser': ua.browser.name,
          'submitUa': ua,
          'wxUserInfo': {},
          'wxOpenId': "",
          'originalData': data.formModel,
          "accessTime":data.accessTime
        }).then(() => {
          this.msgSuccess('提交成功')
          this.goBack()
        })
      }
    }
  }
}
</script>
<style lang="scss" scoped>


.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}

.box-card {
  width: 100%;
  margin-bottom: 20px;
}

.el-tag + .el-tag {
  margin-left: 10px;
}
</style>
